home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-01
/
msoftapp.zip
/
CIRCLE.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1993-06-01
|
8KB
|
295 lines
// circle.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "circle.h"
#include "mainfrm.h"
#include "circfrm.h"
#include "circldoc.h"
#include "circlvw.h"
#include "textview.h"
#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCircleApp
BEGIN_MESSAGE_MAP(CCircleApp, CWinApp)
//{{AFX_MSG_MAP(CCircleApp)
ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
ON_COMMAND(ID_FILE_NEW, OnFileNew)
//}}AFX_MSG_MAP
// Standard file based document commands
ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
// Standard print setup command
ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCircleApp construction
CCircleApp::CCircleApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CCircleApp object
CCircleApp NEAR theApp;
/////////////////////////////////////////////////////////////////////////////
// CCircleApp initialization
BOOL CCircleApp::InitInstance()
{
// Initialize VBX Runtime support by adding this line:
EnableVBX();
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.
SetDialogBkColor(RGB(255,255,255)); // set dialog background color to gray
LoadStdProfileSettings(); // Load standard INI file options (including MRU)
// We create two doc template objects to orchestrate the creation of two
// distinct MDI children-hosted views of the document: (1) the check
// check view and (2) the book view.
//
// We register both doc templates with the CWinApp object, by calling
// AddDocTemplate. However, if we were to do this and nothing else, then
// the framework would mistakenly believe that the application supports
// two document types. The framework would display a File New dialog
// that lists two document types, both which would be "Circle".
// We avoid this problem by removing the third string from
// the document template for the text frame/view. Specifically,
// the strings for documents IDR_GRAPHICFRAME and IDR_TEXTFRAME are,
// respectively:
//
// "GraphicView\nCircle\nCircle\n
// Circle File (*.cir)\n.cir\n
// CircleFileType\nCircle File Type"
// and
// "TextView\nCircle\n\n
// Circle File (*.cir)\n.cir\n
// CircleFileType\nCircle File Type"
//
// Finding no GetDocString(CDocTemplate::fileNewName) for the
// second document template, CWinApp concludes that there is only
// one document type supported by the application (the "Circle"
// document type specified in the first document template; and
// therefore does not present the user with a File New dialog.
m_pGraphicViewTemplate = new CMultiDocTemplate(IDR_GRAPHICFRAME,
RUNTIME_CLASS(CCircleDoc),
RUNTIME_CLASS(CCircleFrame),
RUNTIME_CLASS(CGraphicView));
AddDocTemplate(m_pGraphicViewTemplate);
m_pTextViewTemplate = new CMultiDocTemplate(IDR_TEXTFRAME,
RUNTIME_CLASS(CCircleDoc),
RUNTIME_CLASS(CCircleFrame),
RUNTIME_CLASS(CTextView));
AddDocTemplate(m_pTextViewTemplate);
// create main MDI Frame window
CMainFrame* pMainFrame = new CMainFrame;
if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
return FALSE;
pMainFrame->ShowWindow(m_nCmdShow);
pMainFrame->UpdateWindow();
m_pMainWnd = pMainFrame;
// create a new document
OnFileNew();
return TRUE;
}
void CCircleApp::OnFileNew()
{
// Let the default WinApp::OnFileNew() create the 1st (graphic) view, based on the
// document template already "loaded" (in CCircleApp::InitInstance()).
//
CWinApp::OnFileNew();
// Now create the 2nd (text) view explicitly, based on the same document.
//
CView *pViewWnd = (CView *)CWnd::GetFocus();
CCircleDoc* pDoc = (CCircleDoc *) (pViewWnd->GetDocument());
if (pDoc == NULL)
{
return;
}
CFrameWnd* pNewFrame = m_pTextViewTemplate->CreateNewFrame(pDoc, NULL);
if (pNewFrame == NULL)
{
return;
}
m_pTextViewTemplate->InitialUpdateFrame(pNewFrame, pDoc);
// Tile all MDI children windows within the MDI frame window.
//
ASSERT(pNewFrame->IsKindOf(RUNTIME_CLASS(CMDIChildWnd)));
CMDIFrameWnd* pMDIFrameWnd = ((CMDIChildWnd*)pNewFrame)->GetMDIFrame();
ASSERT(pMDIFrameWnd != NULL);
pMDIFrameWnd->MDITile(MDITILE_HORIZONTAL);
}
CDocument* CCircleApp::OpenDocumentFile(LPCSTR lpszFileName)
{
// CWinApp::OpenDocmentFile creates the first MDI child window
// for the graphic view. This override creates the second MDI child
// window for the text view. Then it tiles the two MDI children
// windows.
CCircleDoc* pDoc = (CCircleDoc*)CWinApp::OpenDocumentFile(lpszFileName);
if (pDoc == NULL)
{
// CString strMessage;
// AfxFormatString1(strMessage, IDS_CANNOT_OPEN_CHECKBOOK,
// lpszFileName);
// AfxMessageBox(strMessage);
return NULL;
}
CFrameWnd* pNewFrame = m_pTextViewTemplate->CreateNewFrame(pDoc, NULL);
if (pNewFrame == NULL)
return pDoc;
m_pTextViewTemplate->InitialUpdateFrame(pNewFrame, pDoc);
// Tile the two MDI children windows within the MDI frame window.
ASSERT(pNewFrame->IsKindOf(RUNTIME_CLASS(CMDIChildWnd)));
CMDIFrameWnd* pMDIFrameWnd = ((CMDIChildWnd*)pNewFrame)->GetMDIFrame();
ASSERT(pMDIFrameWnd != NULL);
pMDIFrameWnd->MDITile(MDITILE_HORIZONTAL);
return pDoc;
}
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
CVBControl* m_pCircle;
COLORREF m_BackColor;
int m_Top;
int m_Left;
//}}AFX_DATA
// Implementation
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//{{AFX_MSG(CAboutDlg)
afx_msg void OnClickinCircle1(UINT, int, CWnd*, LPVOID);
afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
m_pCircle = NULL;
m_BackColor = RGB(255,0,0);
m_Top = 0;
m_Left = 0;
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
DDX_VBControl(pDX, IDC_CIRCLE1, m_pCircle);
DDX_VBColor(pDX, IDC_CIRCLE1, 2, m_BackColor);
DDX_VBInt(pDX, IDC_CIRCLE1, 4, m_Top);
DDX_VBInt(pDX, IDC_CIRCLE1, 3, m_Left);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
ON_VBXEVENT(VBN_CLICKIN, IDC_CIRCLE1, OnClickinCircle1)
ON_WM_LBUTTONDBLCLK()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
// App command to run the dialog
void CCircleApp::OnAppAbout()
{
CAboutDlg aboutDlg;
aboutDlg.DoModal();
}
void CAboutDlg::OnClickinCircle1(UINT, int, CWnd*, LPVOID)
{
// bounce the ball - method 1
for (int i=0; i < 50; i++)
{
m_Top += 4;
m_Left += 4;
UpdateData(FALSE);
UpdateWindow();
}
// bounce the ball - method 2
for (int j=50; j > 0; j--)
{
m_Top -= 4;
m_Left -= 4;
m_pCircle->SetNumProperty("Top", j);
m_pCircle->SetNumProperty("Left",j);
UpdateWindow();
}
}
//{{AFX_VBX_REGISTER_MAP()
UINT NEAR VBN_CLICKIN = AfxRegisterVBEvent("CLICKIN");
//}}AFX_VBX_REGISTER_MAP
void CAboutDlg::OnLButtonDblClk(UINT nFlags, CPoint point)
{
// bounce the ball - method 1
for (int i=0; i < 50; i++)
{
m_Top += 4;
m_Left += 4;
UpdateData(FALSE);
UpdateWindow();
}
// bounce the ball - method 2
for (int j=50; j > 0; j--)
{
m_Top -= 4;
m_Left -= 4;
m_pCircle->SetNumProperty("Top", j);
m_pCircle->SetNumProperty("Left",j);
UpdateWindow();
}
CDialog::OnLButtonDblClk(nFlags, point);
}